/*
 * HomeCategoryHolder.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.viewholder;

import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.imagemodule.Menu;
import com.yidiandao.business.data.imagemodule.MenuInfo;
import com.yidiandao.business.ui.widget.listview.ViewHolder;
import com.yidiandao.business.ui.widget.view.RatioLayout;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.UIUtils;

/** 首页酒类ViewHolder */
public class HomeMenuHolder extends ViewHolder {

    public LinearLayout mRootMenu1;
    public LinearLayout mRootMenu2;
    public LinearLayout mRootMenu3;
    public LinearLayout mRootMenu4;
    public LinearLayout mRootMenu5;
    public LinearLayout mRootMenu6;
    public LinearLayout mRootMenu7;
    public LinearLayout mRootMenu8;
    private RatioLayout mOuterRatioLayout;
    private LinearLayout mLine1;
    private ImageView mIvMenu1;
    private TextView mTvMenuName1;
    private ImageView mIvMenu2;
    private TextView mTvMenuName2;
    private ImageView mIvMenu3;
    private TextView mTvMenuName3;
    private ImageView mIvMenu4;
    private TextView mTvMenuName4;
    private LinearLayout mLine2;
    private ImageView mIvMenu5;
    private TextView mTvMenuName5;
    private ImageView mIvMenu6;
    private TextView mTvMenuName6;
    private ImageView mIvMenu7;
    private TextView mTvMenuName7;
    private ImageView mIvMenu8;

    private TextView mTvMenuName8;

    private ImageView mIvBgImage;

    @Override
    protected void initView(View rootView) {
        mOuterRatioLayout = (RatioLayout) rootView.findViewById(R.id.outer_ratio_layout);
        mLine1 = (LinearLayout) rootView.findViewById(R.id.line_1);
        mRootMenu1 = (LinearLayout) rootView.findViewById(R.id.root_menu_1);
        mIvMenu1 = (ImageView) rootView.findViewById(R.id.iv_menu_1);
        mTvMenuName1 = (TextView) rootView.findViewById(R.id.tv_menu_name_1);
        mRootMenu2 = (LinearLayout) rootView.findViewById(R.id.root_menu_2);
        mIvMenu2 = (ImageView) rootView.findViewById(R.id.iv_menu_2);
        mTvMenuName2 = (TextView) rootView.findViewById(R.id.tv_menu_name_2);
        mRootMenu3 = (LinearLayout) rootView.findViewById(R.id.root_menu_3);
        mIvMenu3 = (ImageView) rootView.findViewById(R.id.iv_menu_3);
        mTvMenuName3 = (TextView) rootView.findViewById(R.id.tv_menu_name_3);
        mRootMenu4 = (LinearLayout) rootView.findViewById(R.id.root_menu_4);
        mIvMenu4 = (ImageView) rootView.findViewById(R.id.iv_menu_4);
        mTvMenuName4 = (TextView) rootView.findViewById(R.id.tv_menu_name_4);
        mLine2 = (LinearLayout) rootView.findViewById(R.id.line_2);
        mRootMenu5 = (LinearLayout) rootView.findViewById(R.id.root_menu_5);
        mIvMenu5 = (ImageView) rootView.findViewById(R.id.iv_menu_5);
        mTvMenuName5 = (TextView) rootView.findViewById(R.id.tv_menu_name_5);
        mRootMenu6 = (LinearLayout) rootView.findViewById(R.id.root_menu_6);
        mIvMenu6 = (ImageView) rootView.findViewById(R.id.iv_menu_6);
        mTvMenuName6 = (TextView) rootView.findViewById(R.id.tv_menu_name_6);
        mRootMenu7 = (LinearLayout) rootView.findViewById(R.id.root_menu_7);
        mIvMenu7 = (ImageView) rootView.findViewById(R.id.iv_menu_7);
        mTvMenuName7 = (TextView) rootView.findViewById(R.id.tv_menu_name_7);
        mRootMenu8 = (LinearLayout) rootView.findViewById(R.id.root_menu_8);
        mIvMenu8 = (ImageView) rootView.findViewById(R.id.iv_menu_8);
        mTvMenuName8 = (TextView) rootView.findViewById(R.id.tv_menu_name_8);
        mIvBgImage = (ImageView) rootView.findViewById(R.id.iv_bg_image);
    }

    public void refreshUI(
            Menu menu1,
            Menu menu2,
            Menu menu3,
            Menu menu4,
            Menu menu5,
            Menu menu6,
            Menu menu7,
            Menu menu8) {

        ImageLoader.loadImage(mContext, mIvMenu1, menu1.getMenuImg());
        ImageLoader.loadImage(mContext, mIvMenu2, menu2.getMenuImg());
        ImageLoader.loadImage(mContext, mIvMenu3, menu3.getMenuImg());
        ImageLoader.loadImage(mContext, mIvMenu4, menu4.getMenuImg());

        mTvMenuName1.setText(menu1.getMenuName());
        mTvMenuName2.setText(menu2.getMenuName());
        mTvMenuName3.setText(menu3.getMenuName());
        mTvMenuName4.setText(menu4.getMenuName());

        try {

            ImageLoader.loadImage(mContext, mIvMenu5, menu5.getMenuImg());
            ImageLoader.loadImage(mContext, mIvMenu6, menu6.getMenuImg());
            ImageLoader.loadImage(mContext, mIvMenu7, menu7.getMenuImg());
            ImageLoader.loadImage(mContext, mIvMenu8, menu8.getMenuImg());

            mTvMenuName5.setText(menu5.getMenuName());
            mTvMenuName6.setText(menu6.getMenuName());
            mTvMenuName7.setText(menu7.getMenuName());
            mTvMenuName8.setText(menu8.getMenuName());

        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_home_menu;
    }

    public void setLine2Gone() {
        mLine2.setVisibility(View.GONE);
        // 单行的宽高比
        mOuterRatioLayout.setRatio(4.536f);
    }

    public void refreshBackground(MenuInfo.Font font) {
        if (font != null) {
            ImageLoader.loadImage(mContext, mIvBgImage, font.getImage());
            mTvMenuName1.setTextColor(Color.parseColor(font.getColor()));
            mTvMenuName2.setTextColor(Color.parseColor(font.getColor()));
            mTvMenuName3.setTextColor(Color.parseColor(font.getColor()));
            mTvMenuName4.setTextColor(Color.parseColor(font.getColor()));
            mTvMenuName5.setTextColor(Color.parseColor(font.getColor()));
            mTvMenuName6.setTextColor(Color.parseColor(font.getColor()));
            mTvMenuName7.setTextColor(Color.parseColor(font.getColor()));
            mTvMenuName8.setTextColor(Color.parseColor(font.getColor()));
        } else {
            mIvBgImage.setBackgroundColor(Color.WHITE);
            mTvMenuName1.setTextColor(UIUtils.getColor(R.color.text_color_3));
            mTvMenuName2.setTextColor(UIUtils.getColor(R.color.text_color_3));
            mTvMenuName3.setTextColor(UIUtils.getColor(R.color.text_color_3));
            mTvMenuName4.setTextColor(UIUtils.getColor(R.color.text_color_3));
            mTvMenuName5.setTextColor(UIUtils.getColor(R.color.text_color_3));
            mTvMenuName6.setTextColor(UIUtils.getColor(R.color.text_color_3));
            mTvMenuName7.setTextColor(UIUtils.getColor(R.color.text_color_3));
            mTvMenuName8.setTextColor(UIUtils.getColor(R.color.text_color_3));
        }
    }
}
